#CC=/opt/Embedsky/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/tq-linaro-toolchain/bin/arm-none-linux-gnueabi-gcc
#CC=/opt/EmbedSky/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/tq-linaro-toolchain/bin/arm-none-linux-gnueabi-gcc
CC = gcc

ifndef CFLAGS
CFLAGS = -MMD -O2 -O0 -ggdb3 -Wall -g
endif

LIBS = 
CFLAGS += $(EXTRA_CFLAGS)
CFLAGS += -I$(abspath ./message)
CFLAGS += -I$(abspath ./network)
CFLAGS += -I$(abspath ./carcontrol)
CFLAGS += -I$(abspath ./include)
#CFLAGS += -I$(abspath ./thirdparty/libevent-2.1.8-stable)
#CFLAGS += -I$(abspath ./thirdparty/libevent-2.1.8-stable/include)
LDFLAGS += -L$(abspath ./lib)
LDFLAGS += -L/usr/lib
#LDFLAGS += -L$(abspath ./thirdparty/libevent-2.1.8-stable/.libs)
LDFLAGS += -L$(abspath ./thirdparty/cJSON)
#export BINDIR ?= /usr/local/bin/

OBJS = ./carcontrol/car_move_pi4.o
OBJS += ./carcontrol/car_control_pi4.o
OBJS += ./carcontrol/serial.o
#OBJS += ./carcontrol/gpio.o
#OBJS += ./carcontrol/pwm.o
OBJS += ./message/msg.o
OBJS += ./message/ctl_car_msg.o
OBJS += ./message/ctl_hand_msg.o
OBJS += ./message/result_msg.o
OBJS += ./network/server.o
OBJS_MAIN = main.o $(OBJS)
OBJS_CLIENT = client.o $(OBJS)

#CFLAGS += -levent  -levent_core  -levent_extra  -levent_openssl  -levent_pthreads
LIBS +=  -lwiringPi -lwiringPiDev -ldl -lm -lcjson -lcjson_utils -levent  -levent_core  -levent_extra  -levent_pthreads -lrt -lpthread 
#-lcrypto -levent_openssl


all : client main

Q=@
E=echo
ifeq ($(V), 1)
Q=
E=true
endif
ifeq ($(QUIET), 1)
Q=@
E=true
endif


#$(DESTDIR)$(BINDIR)/%: %
#	install -D $(<) $(@)

#install: $(addprefix $(DESTDIR)$(BINDIR)/,$(ALL))


client: $(OBJS_CLIENT)
	$(CC) $(LDFLAGS) -o client $(OBJS_CLIENT) $(LIBS)
	@$(E) "  LD " $@


main: $(OBJS_MAIN)
	$(CC) $(LDFLAGS) -o main $(OBJS_MAIN) $(LIBS)
	@$(E) "  LD " $@


clean:
	rm -f main *.d *.o ./carcontrol/*.o ./carcontrol/*.d ./message/*.o ./message/*.d ./network/*.o ./network/*.d client
	

-include $(OBJS:%.o=%.d)
